<?php

namespace Console\Logic;

use \Common\Logic\BaseLogic;

/**
 * 客服logic
 */
class OnlineLogic extends BaseLogic
{

    private $onlineModel;

    public function __construct()
    {
        parent::__construct();
        $this->onlineModel = D('Online');
    }


    /**
     * 获取客服
     * @param array $where
     * @return mixed
     */
    public function getInfo($where = array())
    {
        $info = $this->onlineModel->where($where)->find();
        return static::$res->suc("成功", $info);
    }


    /**
     * 编辑客服
     * @param $id
     * @param $userId
     * @param array $param
     * @return mixed
     */
    public function edit($id, $userId, $param = array())
    {
        if (empty($id)) {
            return static::$res->err("id不能为空");
        }

        if (empty($userId)) {
            return static::$res->err("编辑人不能为空");
        }

        $where = array(
            "id" => $id
        );

        unset($param['id']);

        $param['edit_time'] = date('Y-m-d H:i:s');
        $param['edit_id'] = $userId;

        $count = $this->onlineModel->where($where)->save($param);
        if (empty($count)) {
            return static::$res->err("数据库异常，没有任何改变");
        }

        return static::$res->suc("操作成功");
    }
}
